#!/bin/bash

a[0]="perl -pe 's/[\n\t]//g'"
a[1]="perl -pe 's/\/\*.+?\*\///g'"
a[2]="perl -pe 's/  +/ /g'"
a[3]="perl -pe 's/\s?({)\s?(.+?);?(})/\1\2\3/g'"
a[4]="perl -pe 's/\s(\!important)/\1/g'"

for f in "$@"
do
	case $(echo "$f" | grep -Po "\.(css|html?)$") in
		".htm" | ".html")
			cat "$f" | perl -pe 's/(^\s+|\n|\t)//g' | eval "${a[2]}"
		;;
		".css")
			cat "$f" | eval "${a[0]}" | eval "${a[1]}" | eval "${a[2]}" | eval "${a[3]}" | eval "${a[4]}"
		;;
		*)
			return
		;;
	esac
done